﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Web;

using OgilvyOne.Model;

/// <summary>
///SessionSimulator 的摘要说明
/// </summary>
public class SessionSimulator
{
    public static Hashtable SessionTable = new Hashtable();

    public SessionSimulator()
    {
        //
        //TODO: 在此处添加构造函数逻辑
        //
    }

    public static bool RegisterSession(string key, string mac, object obj)
    {
        bool result = false;
        try
        {

            lock (SessionTable)
            {
                if (!SessionTable.Contains(key + mac))
                    SessionTable.Add(key + mac, obj);
            }

            result = true;
        }
        catch
        {
            result = false;
        }

        return result;
    }

    public static bool DeregisterSession(string key, string mac)
    {
        bool result = false;
        try
        {
            lock (SessionTable)
            {
                if (SessionTable.Contains(key + mac))
                {
                    SessionTable.Remove(key + mac);
                }
            }

            result = true;
        }
        catch
        {
            result = false;
        }

        return result;
    }

    public static object GetSessionData(string key, string mac)
    {
        object obj = null;
        try
        {
            lock (SessionTable)
            {
                if (SessionTable.Contains(key + mac))
                {
                    obj = SessionTable[key + mac];
                }
            }
        }
        catch
        {
            obj = null;
        }

        return obj;
    }
}
